<?php

/**
 * @package Framework03
 * @author Walter Tamboer
 */

/**
 * Render a XSL template
 */
class XslRenderDevice extends RenderDevice
{
	/**
	 * @var DOMDocument The XML DOM document.
	 */
	private $Xml;
	/**
	 * @var XSLTProcessor The XSL serializer.
	 */
	private $Xsl;
	/**
	 * @var string The XSL file used to process XML.
	 */
	private $XslFile;
	/**
	 * Initializes a new instance of this class.
	 * @param string $XslFile The XSL file used to process XML.
	 * @param DOMDocument $Xml The DOMDocument to use.
	 */
	public function __construct($XslFile, DOMDocument $Xml)
	{
		if (!extension_loaded('xsl'))
		{
			trigger_error("Xsl extension isn't loaded!", E_USER_ERROR);
			exit;
		}

		parent::__construct(array());

		$this->XslFile = $XslFile;
		$this->Xml = $Xml;
	}
	/**
	 * Gets the rendered content.
	 * @return string Returns a string with the parsed content.
	 */
	public function Render()
	{
		// Create the XSL document
		$Temp = new DOMDocument;
		$Temp->load($this->XslFile);

		// Create the XSL translator
		$this->Xsl = new XSLTProcessor();
		$this->Xsl->importStylesheet($Temp);

		echo $this->Xsl->transformToXml($this->Xml);
	}
}

?>